package com.lc.cehui.ui.fragment;

import android.os.Bundle;
import android.view.View;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppFragment;
import com.lc.cehui.http.request.MyCollectApi;
import com.lc.cehui.http.response.CollectListOtherBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.ui.activity.mine.CollectionActivity;
import com.lc.cehui.ui.adapter.CollectionOtherAdapter;
import com.lc.cehui.util.SPUtil;
import com.scwang.smart.refresh.header.MaterialHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class CollectionOtherFragment extends AppFragment<CollectionActivity> {
    private static final String ARG_PARAM1 = "param1";
    @BindView(R.id.addr_recycle)
    RecyclerView addrRecycle;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    private String system_id;
    private List<CollectListOtherBean.DataBean.ListBean> dataList = new ArrayList<>();
    private CollectionOtherAdapter adapter;
    private  int mPage=1;
    private String flag;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_collectionother;
    }

    @Override
    protected void initView() {
        my_collect_list();
    }

    @Override
    protected void initData() {

    }
    public static CollectionOtherFragment newInstance(String system_id) {
        CollectionOtherFragment fragment = new CollectionOtherFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, system_id);

        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            system_id = getArguments().getString(ARG_PARAM1);

        }
    }
    private void my_collect_list() {
        EasyHttp.post(this)
                .api(new MyCollectApi().setPage(mPage).setUserid(SPUtil.get(getContext(), IntentKey.USERID,0)).setType(2))
                .request(new HttpCallback<CollectListOtherBean>(this) {

                    @Override
                    public void onSucceed(CollectListOtherBean data) {

                        if (data.getCode().equals("200")) {
                            flag = data.getFlag();
                               if (data.getData()!=null) {
                                   dataList.addAll(data.getData().getList());
                                   adapter.setData(dataList);

                               }

                        }

                    }
                });
    }
    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        addrRecycle.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter= new CollectionOtherAdapter(getContext(),dataList);
        addrRecycle.setAdapter(adapter);
        refreshLayout.setRefreshHeader(new MaterialHeader(getContext()));
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh( RefreshLayout refreshLayout) {

            }
        });
    }
}
